package cn.edu.ctbu.myfirstweb.webapi;

import cn.edu.ctbu.myfirstweb.domain.Course;
import cn.edu.ctbu.myfirstweb.domain.Student;
import cn.edu.ctbu.myfirstweb.domain.StudentScore;
import cn.edu.ctbu.myfirstweb.helper.R;
import cn.edu.ctbu.myfirstweb.helper.REnum;
import cn.edu.ctbu.myfirstweb.helper.RUtil;
import cn.edu.ctbu.myfirstweb.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
public class StudentScoreRestController {
    @Autowired
    StudentService studentService;


    /**
    * @Description: 获取学生的已修课程信息
    * @Param:
    * @Return:
    * @Author: HighJ
    * @Date Created in
    */

    @GetMapping("/getscore")
    public R<List<StudentScore>> getscore(HttpServletRequest request) {
        Student student = (Student) request.getSession().getAttribute("SYSTEM_USER_SESSION");
        List<StudentScore> studentScores = studentService.getStudentScore(student.getNum());
        if (studentScores != null) {
            return RUtil.success(studentScores);
        }
        return RUtil.error(REnum.UNKNOWN_ERR);
    }
    /**
    * @Description: 通过登录学生学号查询其本期可选课程
    * @Param:
    * @Return:
    * @Author: HighJ
    * @Date Created in
    */

    @GetMapping("/getcourse")
    public R<List<Course>> getcourse(HttpServletRequest request) {
        Student student = (Student) request.getSession().getAttribute("SYSTEM_USER_SESSION");
        List<Course> studentCourse = studentService.getStudentCourse(student.getNum());
        if (studentCourse != null) {
            return RUtil.success(studentCourse);
        }
        return RUtil.error(REnum.UNKNOWN_ERR);
    }
    /**
    * @Description:  通过登录学生学号查询其本期已经选了的课程
    * @Param:
    * @Return:
    * @Author: HighJ
    * @Date Created in
    */

    @GetMapping("/getthiscourse")
    public R<List<Course>> getthiscourse(HttpServletRequest request) {
        Student student = (Student) request.getSession().getAttribute("SYSTEM_USER_SESSION");
        List<Course> studentCourse = studentService.getThisSemesterCourse(student.getNum());
        if (studentCourse != null) {
            return RUtil.success(studentCourse);
        }
        return RUtil.error(REnum.UNKNOWN_ERR);
    }


}
